/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package blms.services;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import blms.domain.League;
import blms.domain.User;
import blms.exception.LeagueDoesNotExistException;
import blms.exception.RestrictionException;
import blms.exception.UserDoesNotExistException;
import blms.exception.ValidationException;

/**
 * This service handles creation, update and deletion of leagues. It is a service
 * interface to CRUD operations.
 * 
 * @author Jonhnny Weslley
 * @author Thiago Emmanuel Pereira da Cunha Silva, thiago.manel@gmail.com
 * @version 1.00, 22/04/2008
 * @since 1.0
 */
public interface LeagueService {

	/**
	 * Creates and add a new league.
	 * 
	 * @param name
	 *            The league name
	 * @param operator
	 *            The operator email
	 * @param Date
	 * 			The league creation date
	 * 
	 * @return an identifier to the league
	 * 
	 * @throws UserDoesNotExistException
	 *             The operator should be a valid user in the system.
	 * @throws ValidationException
	 * @throws RestrictionException 
	 */
	League createLeague(String name, String operator, Date object)
			throws UserDoesNotExistException, ValidationException, RestrictionException;

	/**
	 * Looks up a league.
	 * 
	 * @param id
	 * @return
	 * @throws LeagueDoesNotExistException
	 *             Throwed if there is not a league with the id parameter
	 */
	League getLeague(Serializable id) throws LeagueDoesNotExistException;

	/**
	 * Returns <tt>true</tt> if there is an league with the specified id.
	 * 
	 * @param id
	 * @return <tt>true</tt> if there is an league with the specified id.
	 */
	boolean contains(Serializable id);

	/**
	 * Returns <tt>true</tt> if there is an league with the specified name.
	 * 
	 * @param email
	 * @return <tt>true</tt> if there is an league with the specified name.
	 */
	boolean containsLeagueWithName(String name);

	/**
	 * Find the leagues which the player is a member
	 * 
	 * @param idStronger
	 * @throws UserDoesNotExistException
	 */
	List<League> getPlayerLeagues(Serializable id)
			throws UserDoesNotExistException;

	/**
	 * Finds the league with the specified name.
	 * 
	 * @param name
	 *            The name of the league to be found.
	 * @return The league with the specified name.
	 * @throws LeagueDoesNotExistException
	 */
	List<String> findLeagueByName(String name)
			throws LeagueDoesNotExistException;

	/**
	 * @param newLeague
	 * @throws ValidationException
	 */
	void updateLeague(League league) throws ValidationException;

	/**
	 * Removes the specified user from the system.
	 * 
	 * @param id
	 *            The id of the user to be removed.
	 * @throws LeagueDoesNotExistException
	 */
	void deleteLeague(Serializable id) throws LeagueDoesNotExistException;

	/**
	 * Cleans the internal state, removing all leagues.
	 */
	void removeAllLeagues();

	/**
	 * Binds a specified user to a league.
	 * 
	 * @param league
	 * @param user
	 * @param initialHandicap
	 * @throws ValidationException
	 * @throws RestrictionException 
	 */
	void join(League league, User user, int initialHandicap)
			throws ValidationException, RestrictionException;

	/**
	 * @param league
	 * @param user
	 * @throws RestrictionException 
	 */
	void leave(League league, User user) throws RestrictionException;
}